from studio.models import Studio,AppModel
from studio import app_info

def get_globals():
    return globals()

def update_app(sku,studio_name):
    print('system notify changed : app_sku={sku} of studio={studio}'.format(sku=sku,studio=studio_name))
    try:
        studio = Studio.objects.get(name=studio_name)
        app_info.update_app(sku, studio_name)
        # tasks.update_app_with_celery.delay(sku, studio_name)
        # app_info.update_app(sku, studio_name)
        studio.save()   # update the moify time ,so can trigger auto deploy
        print('[commands.update_app]update studio_name=%s \'s app_sku= %s  complete'%(studio_name,sku))
        return {'status':'success'}
    except Studio.DoesNotExist as e :
        print('%s not exist in APG system yet'%studio_name)
        return {'msg':'%s not exist in APG system yet'%studio_name}
    